all:
	@echo "本次构建为说明: "
	@echo "  1. 进入 venv 模式"
	@echo "  2. 使用 pip 安装 streamlit"
	@echo "  3. 执行 streamlit run welcom.py，可使用 make run"


WHICH_STREAMLIT=$(shell which streamlit)
ifneq ($(WHICH_STREAMLIT),)
run:
	@streamlit run welcome.py
else 
run:
	@echo "NOTE: 当前环境中未发现 streamlit ，确保已执行 pip install streamlit"
endif

NAME=streamlit-spk-online-builder
REPO=

$(NAME):
	docker build -t $(REPO)$(@):latest .

ifneq ($(REPO),)

$(NAME)-push: $(NAME)
	docker push $(REPO)$(@):latest

$(NAME)-deploy: $(NAME)-push
	docker service update --image $(REPO)$(@):latest $(@)
endif

docker-$(NAME)-start: $(NAME)
	docker run --name $(NAME)-container -d -p 8501:8501 --restart always -v /var/run/docker.sock:/var/run/docker.sock -v /tmp/.spk-online-workdir:/tmp/.spk-online-workdir $(NAME):latest  
	docker logs $(NAME)-container
	
docker-$(NAME)-stop: 
	docker stop $(NAME)-container

docker-$(NAME)-rm: docker-$(NAME)-stop
	docker rm $(NAME)-container


# 说明: 本地、容器运行
 # 1. make run 命令，用于本地运行
 # 2. make docker-xxx-start 命令，用于启动容器，并运行
 # 3. make docker-xxx-stop 命令，用于停止容器
 # 4. make docker-xxx-rm 命令，用于删除容器

# 其它: REPO 变量，用于指定镜像仓库地址
 # 1. make docker-xxx-push 命令，用于推送镜像到仓库
 # 2. make docker-xxx-deploy 命令，用于部署镜像到 swarm 集群